package com.flx.noodle.websocket.service;

import com.flx.noodle.websocket.dao.MessageDao;
import com.flx.noodle.websocket.entity.ChatMessage;
import com.flx.noodle.websocket.searcher.MessageSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fenglixiong on 2017/10/4.
 */
@Service
public class MessageService {

    @Autowired
    private MessageDao messageDao;

    public ChatMessage getMessageById(int messageId){
        return messageDao.getMessageById(messageId);
    }

    public int saveOrUpdate(ChatMessage chatMessage){
        if(chatMessage.getId()==null){
            return insertMessage(chatMessage);
        }else {
            return updateMessage(chatMessage);
        }
    }

    public int insertMessage(ChatMessage chatMessage){
        return messageDao.insertMessage(chatMessage);
    }

    public int updateMessage(ChatMessage chatMessage){
        return messageDao.updateMessage(chatMessage);
    }

    public int deleteMessage(int messageId){
        return messageDao.deleteMessage(messageId);
    }

    public List<ChatMessage> findMessageList(MessageSearcher searcher){
        return messageDao.findMessageList(searcher);
    }


}
